package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品
     * @param id
     * @return
     */
    @Select("select count(0) from dish where category_id = #{id}")
    Integer countByCategoryId(Long id);

    /**
     * 添加菜品
     * @param dish
     */

    @AutoFill(OperationType.INSERT)
    void addDish(Dish dish);


    /**
     * 分页查询菜品
     * @param dishPageQueryDTO
     * @return
     */
    List<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 更新菜品信息
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据id查询菜品信息
     * @param id
     * @return
     */
    DishVO getById(Long id);

    /**
     * 根据id查询菜品是否启售
     * @param id
     * @return
     */
    @Select("select status from dish where id = #{id}")
    Integer isEnable(Long id);

    /**
     * 批量删除菜品
     * @param ids
     */
    void deleteBatch(List<Long> ids);

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */

    @Select("select * from dish where category_id = #{categoryId} and status = 1")
    List<DishVO> getByCategoryId(Long categoryId);


    /**
     * 根据id查询菜品是否启售
     * @param dishId
     */
    @Select("select status from dish where id = #{dishId}")
    int getEnableById(Long dishId);
    /**
     * 统计启售/停售菜品数量
     * @param status
     * @return
     */
    @Select("select count(id) from dish where status = #{status} ")
    Integer overviewDishes(Integer status);
}
